

sink("R maps log file.txt", split = TRUE)

install.packages("maps")
install.packages("gpclib")
install.packages("maptools")
install.packages("ggplot2")
install.packages("mapdata")

setwd ("/Users/jdarr/Dropbox/Research/Field Offices/2016 Paper/Maps")

library(maps)
library(gpclib)
library(maptools) 
library(ggplot2)
library(mapdata)

data(stateMapEnv)
data(us.cities)


## Figure 1: National maps, 2012-2016
obama08=read.csv("Obama 2008 offices.csv",header=TRUE)
obama12=read.csv("Obama 2012 offices.csv",header=TRUE)
romney12=read.csv("Romney 2012 offices.csv",header=TRUE)
clinton16=read.csv("Clinton 2016 offices.csv",header=TRUE)
trump16=read.csv("Trump 2016 offices.csv",header=TRUE)

jpeg(filename="/Users/jdarr/Dropbox/Research/Field Offices/2016 Paper/Maps/obama08.jpeg",width=2000,height=1100, bg="white")
map('state', plot=TRUE, fill = TRUE, col = 0)
title("Obama 2008", cex.main=5)
points(x=obama12$longitude,y=obama12$latitude,pch=19,col='blue' ,cex=2)
dev.off()

jpeg(filename="/Users/jdarr/Dropbox/Research/Field Offices/2016 Paper/Maps/obama12.jpeg",width=2000,height=1100, bg="white")
map('state', plot=TRUE, fill = TRUE, col = 0)
title("Obama 2012", cex.main=5)
points(x=obama12$longitude,y=obama12$latitude,pch=19,col='blue' ,cex=2)
dev.off()

jpeg(filename="/Users/jdarr/Dropbox/Research/Field Offices/2016 Paper/Maps/romney12.jpeg",width=2000,height=1100, bg="white")
map('state', plot=TRUE, fill = TRUE, col = 0)
title("Romney 2012", cex.main=5)
points(x=romney12$longitude,y=romney12$latitude,pch=19,col='red' ,cex=2)
dev.off()

jpeg(filename="/Users/jdarr/Dropbox/Research/Field Offices/2016 Paper/Maps/clinton16.jpeg",width=2000,height=1100, bg="white")
map('state', plot=TRUE, fill = TRUE, col = 0)
title("Clinton 2016", cex.main=5)
points(x=clinton16$longitude,y=clinton16$latitude,pch=19,col='blue' ,cex=2)
dev.off()

jpeg(filename="/Users/jdarr/Dropbox/Research/Field Offices/2016 Paper/Maps/trump16.jpeg",width=2000,height=1100, bg="white")
map('state', plot=TRUE, fill = TRUE, col = 0)
title("Trump 2016", cex.main=5)
points(x=trump16$longitude,y=trump16$latitude,pch=19,col='red' ,cex=2)
dev.off()



## Figure 2: Wisconsin office maps

obama12=read.csv("Obama 2012 offices - Wisconsin.csv",header=TRUE)
clinton16=read.csv("Clinton 2016 offices - Wisconsin.csv",header=TRUE)

jpeg(filename="/Users/jdarr/Dropbox/Research/Field Offices/2016 Paper/Maps/obama12_wi.jpeg",width=1000,height=1000, bg="white")
map('county', 'wisconsin', plot=TRUE, fill = TRUE, col = 0)
map.cities(x = us.cities, country = "WI", label = NULL, minpop = 90000, maxpop = Inf, cex = 3, pch = 1)
title("Obama 2012", cex.main=5)
points(x=obama12$longitude,y=obama12$latitude,pch=19,col='blue' ,cex=2)
dev.off()

jpeg(filename="/Users/jdarr/Dropbox/Research/Field Offices/2016 Paper/Maps/clinton16_wi.jpeg",width=1000,height=1000, bg="white")
map('county', 'wisconsin', plot=TRUE, fill = TRUE, col = 0)
map.cities(x = us.cities, country = "WI", label = NULL, minpop = 90000, maxpop = Inf, cex = 3, pch = 1)
title("Clinton 2016", cex.main=5)
points(x=clinton16$longitude,y=clinton16$latitude,pch=19,col='blue' ,cex=2)
dev.off()


sink()